//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class ForEach: IOfficeXmlSerializable
    {
        IteratorAttributes _IteratorAttributes = new IteratorAttributes();
        private string _name;
        private string _ref;
        List<IOfficeXmlSerializable> _items = new List<IOfficeXmlSerializable>();

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("forEach"))
            {
                _name = c.GetOptionalString("name", string.Empty);
                _ref = c.GetOptionalString("ref", string.Empty);
                _IteratorAttributes.ReadXml(c);
                _items.Clear();
                _items.AddRange(ReaderHelper.ReadItems(c));

            }

        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("forEach"))
            {
                c.SetOptionalString("name", _name, string.Empty);
                c.SetOptionalString("ref", _ref, string.Empty);
                _IteratorAttributes.WriteXml(c);
                c.WriteElements(_items);

            }
        }
    }
}